3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next
A trimesh is a collection of vertices, edges, and faces in which all faces are triangular. In other words, a trimesh is simply a mesh composed entirely of triangles. A trimesh is like a polyhedron in that its faces are defined indirectly, using indices into an array of vertices. Similarly, the edges of a trimesh are defined by an optional array of edge vertices.
The main difference between trimeshes and all other QuickDraw 3D primitives (including polyhedra) is that attributes for trimesh vertices, edges, and faces are not stored as objects of type TQ3AttributeSet ; rather, those attributes are stored in arrays of explicit attribute data structures. Moreover, if any single vertex (or edge, or face) has an attribute of a specific non-custom type, then every vertex (or edge, or face) in the trimesh must also have an attribute of that type. This restriction can deleteriously affect the memory requirements of a large trimesh.
See "Comparison of the Polyhedral Primitives" for more information on the advantages and disadvantages of using trimeshes to model a polyhedral surface.
A trimesh triangle data structure specifies information about a triangular face of a trimesh. A trimesh triangle data structure is defined by the TQ3TriMeshTriangleData data type.
typedef struct TQ3TriMeshTriangleData {
unsigned long pointIndices[3];
} TQ3TriMeshTriangleData;
A trimesh edge data structure specifies information about an edge of a trimesh; it is defined by the TQ3TriMeshEdgeData data structure.
typedef struct TQ3TriMeshEdgeData {
unsigned long pointIndices[2];
unsigned long triangleIndices[2];
} TQ3TriMeshEdgeData;
Attributes for the parts of a trimesh are defined by a trimesh attributes data structure, of type TQ3TriMeshAttributeData .
typedef struct TQ3TriMeshAttributeData {
TQ3AttributeType attributeType;
void *data;
char *attributeUseArray
} TQ3TriMeshAttributeData;
When the attributeType field is set to a pre-defined (that is, non-custom) attribute type, the attributeUseArray field must contain NULL . When the attributeType field is set to a custom attribute type, it should contain a pointer to an array containing only the values 0 and 1. If an element in attributeUseArray has the value 1, then the corresponding vertex (or edge, or face) has a custom attribute; otherwise, if an element in this array has the value 0, the corresponding vertex (or edge, or face) doesn't have a custom attribute.
typedef struct TQ3TriMeshData {
TQ3AttributeSet triMeshAttributeSet;
unsigned long numTriangles;
TQ3TriMeshTriangleData *triangles;
unsigned long numTriangleAttributeTypes;
TQ3TriMeshAttributeData *triangleAttributeTypes;
unsigned long numEdges;
TQ3TriMeshEdgeData *edges;
unsigned long numEdgeAttributeTypes;
TQ3TriMeshAttributeData *edgeAttributeTypes;
unsigned long numPoints;
TQ3Point3D *points;
unsigned long numVertexAttributeTypes;
TQ3TriMeshAttributeData *vertexAttributeTypes;
TQ3BoundingBox bBox;
} TQ3TriMeshData;
You can accelerate trimesh rendering by specifying the trimesh as a strip or fan. A strip is a trimesh whose triangles are ordered sequentially (that is, each triangle has one edge in common with the previous neighboring triangle, a second edge in common with the next neighboring triangle, and the remaining edge in common with no other triangle). A fan is a strip in which all the triangles share a common vertex.
Previous | QD3D Book | Overview | Chapter Contents | Next